/**
 * Description:
 *
 * @author      Eden
 * @datetime    2016/12/4 00:22
 * @copyright   Beijing CmsTop Technology Co.,Ltd.
 */



(function () {
    var api = {
        saveUrl: '/system/about/save'
    };

    sm.controller('admin-system-about', ['$scope', '$http', 'Modal', function ($scope, $http, Modal) {

        $scope.content = '';

        var ue = UE.getEditor('container', {
            'autoClearinitialContent' : false,
            'toolbars' : [['fullscreen', 'source', 'preview', '|', 'bold', 'italic', 'underline', 'strikethrough', 'forecolor', 'backcolor', '|',
                'justifyleft', 'justifycenter', 'justifyright', '|', 'insertorderedlist', 'insertunorderedlist', 'blockquote', 'emotion',
                'link', 'removeformat', 'simpleupload', 'insertimage', '|', 'rowspacingtop', 'rowspacingbottom', 'lineheight','indent', 'paragraph', 'fontsize', '|',
                'inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow', 'insertcol', 'deletecol',
                'mergecells', 'mergeright', 'mergedown', 'splittocells', 'splittorows', 'splittocols', '|', 'anchor', 'map', 'print', 'drafts']],
            'elementPathEnabled' : false,
            'initialFrameHeight': 250,
            'focus' : false,
            'maximumWords' : 999999,
            'zIndex': 999
        });

        $scope.save = function () {
            ue.ready(function () {
                var html = ue.getContent();
                var text = ue.getContentTxt();
                $http.post(api.saveUrl, {content: html, text: text}).success(function (res) {
                    initContent = html;
                    afterPost(res);
                });
            });
        };

        $scope.reset = function () {
            ue.ready(function () {
                ue.setContent(initContent);
            });
        };

        function afterPost(res) {
            if (res.state) {
                Modal.success('设置成功');
            } else {
                var error = res.error ? res.error : '设置失败';
                Modal.error(error);
            }
        }

    }]);
})();